package com.dede.fragmenttest

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val test1Fragment = Test1Fragment()
        val test2Fragment = Test2Fragment()
        supportFragmentManager.beginTransaction()
                .add(R.id.fl_content, test1Fragment)
                .add(R.id.fl_content, test2Fragment)
                .commit()
        navigation.setOnNavigationItemSelectedListener {
            return@setOnNavigationItemSelectedListener when (it.itemId) {
                R.id.menu_bt1 -> {
                    supportFragmentManager.beginTransaction()
                            .show(test1Fragment)
                            .hide(test2Fragment)
//                            .replace(R.id.fl_content, test1Fragment)
                            .commit()
                    true
                }
                R.id.menu_bt2 -> {
                    supportFragmentManager.beginTransaction()
                            .show(test2Fragment)
                            .hide(test1Fragment)
//                            .replace(R.id.fl_content, test2Fragment)
                            .commit()
                    true
                }
                else -> {
                    false
                }
            }
        }
        navigation.selectedItemId = R.id.menu_bt1
    }
}
